<template>
    <el-card><el-form ref="ruleFormRef" label-width="120px" class="demo-ruleForm">
            <el-form-item label="广告名称：" prop="name">
                <el-input v-model="ruleForm.name" />
            </el-form-item>
            <el-form-item label="广告位置：">
                <el-select v-model="ruleForm.type" class="m-2" placeholder="全部" size="default">
                    <el-option label="PC首页轮播" value="0">PC首页轮播</el-option>
                    <el-option label="APP首页轮播" value="1">APP首页轮播</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="开始时间："><el-date-picker v-model="ruleForm.startTime" type="date" placeholder="选择日期"
                    prefix-icon="Clock" />
            </el-form-item>
            <el-form-item label="到期时间：" prop="name"><el-date-picker v-model="ruleForm.endTime" type="date"
                    placeholder="选择日期" prefix-icon="Clock" />
            </el-form-item>
            <el-form-item label="上线/下线："><el-radio-group v-model="ruleForm.status">
                    <el-radio :label="1" size="large">是</el-radio>
                    <el-radio :label="0" size="large">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="广告图片：">
                <!-- /home/advertise/create -->
                <el-upload class="upload-demo" v-model="ruleForm.pic"
                    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" list-type="picture">
                    <el-button type="primary">Click to upload</el-button>
                    <template #tip>
                        <div class="el-upload__tip">
                            jpg/png files with a size less than 500kb
                        </div>

                    </template>
                </el-upload>
            </el-form-item>
            <el-form-item label="排序：" prop="resource"><el-input v-model="ruleForm.sort" />
            </el-form-item>
            <el-form-item label="广告链接："><el-input v-model="ruleForm.url" />
            </el-form-item>
            <el-form-item label="广告备注：">
                <el-input v-model="ruleForm.note" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item>

                <el-button type="primary" @click="onConfirm">提交</el-button>
                <el-button @click="">重置</el-button>

            </el-form-item>
        </el-form></el-card>
</template>
  
<script lang="ts" setup>
import * as tianjia from '../../request/api'
import { ref, onMounted } from 'vue'
import * as advertisement from '../../request/api'
import { Controller } from '../../request/SmsHomeAdvertiseController/index'
import { useRoute,useRouter } from 'vue-router'
import type { Ref } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus'
const ruleForm: any = ref({}) as Ref<Controller>;
let route = useRoute()
let router=useRouter()
let id = route.query.id
console.log(id);

let onConfirm = () => {
    // await advertisement.ment.getreturnReasonUpdate(row)
    ElMessageBox.confirm(
        'proxy will permanently delete the file. Continue?',
        'Warning',
        {
            confirmButtonText: 'OK',
            cancelButtonText: 'Cancel',
            type: 'warning',
        }
    )
        .then(async () => {
            let xixi = ruleForm.value
            await advertisement.ment.getreturnReasonUpdate(xixi)
            setTimeout(()=>{
                router.push('/sms/homeAdvertise')
            },2000)
            ElMessage({
                type: 'success',
                message: 'Delete completed',
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: 'Delete canceled',
            })
        })

};
let updata = async () => {
    let haha = await advertisement.ment.getControllerUpdate({id})
    // console.log(haha);
    
    ruleForm.value = haha
}
updata()
</script>
  
<style lang="scss" scoped>
.el-card {
    margin: 30px auto;
    width: 60%;
    padding: 30px;

    .el-input {
        width: 350px;
    }

    .el-textarea {
        width: 350px;
    }
}
</style>
  